﻿using System;
using System.Collections.Generic;
using System.Text;
using Lswweb.Model;
using Lswweb.Domain;
using Lswweb.Common;
using System.Web.UI.WebControls;

namespace Lswweb.Controls
{
    public class LogisticsCompanyEdit : SkinnedEditControl<LogisticsCompanyInfo>
    {
        private TextBox tbxCompanyName;
        private TextBox tbxWebsite;
        private CheckBox cbxState;

        protected override void InitSkin(System.Web.UI.Control skin)
        {
            tbxCompanyName = skin.FindControl<TextBox>("tbxCompanyName");
            tbxWebsite = skin.FindControl<TextBox>("tbxWebsite");
            cbxState = skin.FindControl<CheckBox>("cbxState");
        }

        protected override void Add(LogisticsCompanyInfo model)
        {
            LogisticsCompanyServices.Insert(model);
        }

        protected override void Update(LogisticsCompanyInfo model)
        {
            LogisticsCompanyServices.Update(model);
        }

        protected override LogisticsCompanyInfo FindById(int id)
        {
            return LogisticsCompanyServices.FindById(id);
        }

        protected override LogisticsCompanyInfo ModelByFrom
        {
            get
            {
                LogisticsCompanyInfo entity = new LogisticsCompanyInfo();

                entity.Id = base.Id;
                entity.CompanyName = tbxCompanyName.GetValue<string>();
                entity.Website = tbxWebsite.GetValue<string>();
                entity.State = cbxState.Checked ? StatusType.Enabled : StatusType.Disabled;

                return entity;
            }
            set
            {
                tbxCompanyName.SetValue(value.CompanyName);
                tbxWebsite.SetValue(value.Website);
                cbxState.Checked = (value.State == StatusType.Enabled);
            }
        }

        protected override string DefaultSkinFilename
        {
            get { return "Logistics/LogisticsCompanyEdit.ascx"; }
        }
    }
}
